import {getFontSize, getLanguage, setFontSize, setLanguage} from "@/utils/auth";
const getDefaultState = () => {
  return {
    fontSize: getFontSize() || 14,
    language: getLanguage() || 'zh'
  }
}
const state = getDefaultState()

const mutations = {
  SET_FONT_SIZE: (state, fontSize) => {
    state.fontSize = fontSize
    setFontSize(fontSize)
    // 移除顶层html的其他fontclass
    document.querySelector('html').classList.forEach(item => {
        if (item.startsWith('font-')) {
            document.querySelector('html').classList.remove(item)
        }
    })
    // 给顶层html添加fontclass
    document.querySelector('html').classList.add(`font-${fontSize}`)
  },
  SET_LANGUAGE: (state, language) => {
    state.language = language
    setLanguage(language)
  },

}

const actions = {

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
